package thread;

class Counts{
    private int count=0;
    public synchronized void add(){
        count++;
    }
    public int get(){
        return count;
    }
}
public class Demo18 {

    public static void main(String[] args) throws InterruptedException {
        Counts counts=new Counts();
        Thread t1=new Thread(()->{
            //可重入
            for(int i=0;i<5000;i++){
                    synchronized (counts) {
                        counts.add();
                    }
            }
        });
        t1.start();
        t1.join();
        System.out.println(counts.get());
    }
}
